<%--
  Created by IntelliJ IDEA.
  User: 檬zhu
  Date: 2022/6/30
  Time: 10:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.ordersystem.domain.RoomAddress" %>
<%@ page import="java.util.List" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<html>
<head>
    <title>选择门店</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/resources/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Lbn1SZBh2NknQy3nUgWl0aspF84KXQma"></script>
</head>
<body>

<table class="layui-table" style="width: 66%;margin-left: 15%">
    <thead>
    <tr>
        <th>店面名称</th>
        <th>店面地址</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        if (request.getAttribute("optsuccess") != null) {
            out.println("<script language='JavaScript'>alert('选择店面成功');");
            return;
        }

        List<RoomAddress> roomAddresses;
        Object obj = request.getAttribute("roomaddress");

        if (obj == null) { //会话过期
            response.sendRedirect("/");
            return; //不再执行接下来的代码
        } else {
            if (obj instanceof JSONArray) {
                roomAddresses = JSON.parseArray(((JSONArray) obj).toJSONString(), RoomAddress.class);
            } else {
                roomAddresses = (List<RoomAddress>) obj;
            }
            int i = 0;
            for (RoomAddress roomAddress : roomAddresses) {

    %>
    <tr>
        <td><%=roomAddress.getName()%>
        </td>
        <td><%=roomAddress.getAddress()%>
        </td>
        <td>
            <form action="${pageContext.request.contextPath}/customer/optroom">
                <button onclick="return window.confirm('确认选择吗？')" class="layui-btn layui-btn-danger layui-btn-sm"
                        name="opt" value="选择">选择
                </button>
                <input type="hidden" name="roomAddress" value="<%=roomAddress.getName()%>">
            </form>
        </td>
    </tr>
    <%

    %>
    <%
                i++;
            }
        }
    %>
    </tbody>
</table>

</body>
</html>
